#include <string.h>  
#include <stdio.h>  
#include <assert.h>  
#include <math.h>  
#include "dominion.h"  
#include "dominion_helpers.h"  
#include "rngs.h" 

void smithyCard( int player , struct gameState *state, int handPos);

void checkSmithy( struct gameState *pre, int handPos, int p ) {
  int i, r, choice1, choice2, choice3;
  struct gameState post;
  
  memcpy(&post, pre, sizeof(struct gameState));
  SelectStream(2);
  PutSeed(3);  
  
  choice1 = floor(Random()*256);
  choice2 = floor(Random()*256);
  choice3 = floor(Random()*256);

  //smithyCard( p, &post, handPos);
  r = cardEffect(smithy, choice1, choice2, choice3, &post, handPos, 0);
  assert( r == 0 );

  for(i=0; i<3; i++)		//Accommodates for bug introduced during previous assignment. Should be "for(i=0; i>3; i++)" to test non-buggy code 
    drawCard( p, pre );
  discardCard(handPos, p, pre, 0);
	
  assert( memcmp(&post, pre, sizeof(struct gameState)) == 0 ); //will throw error if not changed for introduced bug

}



int main() {

  int i, k, n, handPos, p, numPlayers;

  struct gameState g;
	
  PutSeed(3);
  SelectStream(2);
  
  for(n=0; n<2000; n++) {
	
    for(i=0; i<sizeof(struct gameState); i++) 
      ((char *)&g)[i] = floor(Random()*256);
    
    numPlayers = floor(Random()*MAX_PLAYERS);
    p = floor(Random()*numPlayers);

    g.deckCount[p] = floor(Random()*MAX_DECK);
    g.discardCount[p] = floor(Random()*MAX_DECK);
    g.handCount[p] = floor(Random()*MAX_HAND);
	g.playedCardCount = floor(Random()*MAX_HAND);
	for(k=0; k<g.playedCardCount; k++)
		g.playedCards[k] = floor(Random()*MAX_DECK);
    g.numActions = 0;
    g.whoseTurn = p;
    g.numPlayers = numPlayers;
    handPos = floor(Random()*g.handCount[p]);    
    checkSmithy( &g, handPos, p );
  }

  printf("All tests PASSED!\n");
  
  return 0;

}